package com.ym.controller.medical;

import com.github.pagehelper.PageInfo;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.entity.NormalTradeBillEntity;
import com.ym.medical.domain.param.NormalTradeBillQueryParam;
import com.ym.medical.domain.param.NormalTradeBillUpdateParam;
import com.ym.medical.domain.vo.NormalTradeBillListPcVO;
import com.ym.medical.service.INormalTradeBillSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

import static com.ym.common.constant.ValidRule.Add;
import static com.ym.common.constant.ValidRule.Update;

/**
 * 第三方和平台均存在或异常处理后的账单Controller
 * 
 * @author ym
 * @date 2020-09-25
 */
@Api(tags = "medical-第三方和平台均存在或异常处理后的账单")
@RestController
@Validated
@RequestMapping("/medical/normalTradeBill")
public class NormalTradeBillController extends BaseController {

    @Autowired
    private INormalTradeBillSV normalTradeBillSV;

    @ApiOperation("查询第三方和平台均存在或异常处理后的账单列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<NormalTradeBillListPcVO>> list(@Valid NormalTradeBillQueryParam queryParam) {
        PageDomain.startPage();
        List<NormalTradeBillListPcVO> list = normalTradeBillSV.selectListPC(queryParam);
        return successPage(list);
    }

    @ApiOperation("获取第三方和平台均存在或异常处理后的账单详细信息")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<NormalTradeBillEntity> info(@RequestParam Long id) {
        NormalTradeBillEntity data = normalTradeBillSV.selectById(id);
        return successData(data);
    }

    @ApiOperation("新增第三方和平台均存在或异常处理后的账单")
    @Log(printQuery = false)
    @PostMapping("/insert")
    public APIResponse insert(@RequestBody @Validated(value = Add.class) NormalTradeBillUpdateParam updateParam) {
        Long id = normalTradeBillSV.insertPC(updateParam);
        return successData(id);
    }

    @ApiOperation("修改第三方和平台均存在或异常处理后的账单")
    @Log(printQuery = false)
    @PostMapping("/update")
    public APIResponse update(@RequestBody @Validated(value = Update.class) NormalTradeBillUpdateParam updateParam) {
        int result = normalTradeBillSV.updateByIdPC(updateParam);
        return successData(result);
    }

    @ApiOperation("删除第三方和平台均存在或异常处理后的账单")
    @Log(printQuery = false)
    @PostMapping("/delete")
    public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
        int result = normalTradeBillSV.deleteByIds(ids);
        return successData(result);
    }
}
